package TDAPila;

public class LinkedStack <E> implements Stack <E>{
	protected Nodo <E> tope;
	protected int size; 
  
	public LinkedStack(){
		tope=null;
		size=0;}
	
	public int size(){ return size;}
	
	public boolean isEmpty(){
		if (tope==null) return true;
		return false;}
	
	public void push(E element){
		Nodo <E> v = new Nodo<E>(element, tope,null); 
		tope= v;
		size++;}
	
	public E top() throws EmptyStackException{
		if (isEmpty()) throw new EmptyStackException("La pila esta vacia");
		return tope.getElement();}
	
	public E pop() throws EmptyStackException{
		if (isEmpty()) throw new EmptyStackException("La pila esta vacia");
		E temp=tope.getElement();
		tope=tope.getNext();
		size--;
		return temp;}	
}
 

